﻿using System;
using System.Collections.Generic;
using Orid.Management.Statistics.Tools.Decomposition.Model;
using Orid.Management.Common.Job;

namespace Orid.Management.Statistics.Tools.Decomposition.Data
{
    class ChildDatdaOffline : ChildData
    {
        string connectString;
        string ChildDatasTableName;

        public ChildDatdaOffline()
        {
            connectString = Config.Setting.SettingInstance.DBAddress_Offline;
            ChildDatasTableName = Config.Setting.SettingInstance.ChildDatas_Offline;
        }

        Account account = new AccountOffline();
        DataStore dataSotre = new DataStoreOffline();

        public override ModelFrameObject GetFrameData(Guid ChildDataID)
        { 
            try
            {
                if (ChildDataID == null)
                {
                    return null;
                }              

               
               ModelFrameObject model = GetFrameData(ChildDataID, connectString, ChildDatasTableName);

               if ((model!=null) &&(model.DataStoreID != null))
               {
                   model.FileSize = dataSotre.GetFileSize(model.DataStoreID);
               }
               return model;
            }
            catch (Exception ex)
            {
                throw ex;
            } 

        }

        public override ModelBlockObject GetBlockData(Guid ChildDataID)
        {
            
            try
            {
                if (ChildDataID == null)
                {
                    return null;
                }

                ModelBlockObject model = GetBlockData(ChildDataID, connectString, ChildDatasTableName);

                if ((model!=null) &&(model.DataStoreID != null))
                {
                    model.FileSize = dataSotre.GetFileSize(model.DataStoreID);
                }
                return model;

            }
            catch (Exception ex)
            {
                throw ex;
            }

         
         

        }

        public override ModelJudgeObject GetJudgeData(Guid ChildDataID)
        { 
            try
            {

                if (ChildDataID == null)
                {
                    return null;
                }

                ModelJudgeObject model = GetJudgeData(ChildDataID, connectString, ChildDatasTableName ,new AccountOffline());
                if ((model!=null) &&(model.DataStoreID != null))
                {
                    model.FileSize = dataSotre.GetFileSize(model.DataStoreID);
                }
                return model;


            }
            catch (Exception ex)
            {
                throw ex;
            }

     

            
        }

        public override ModelInputObject GetInputObject(Guid ChildDataID)
        {

            try
            {
                if (ChildDataID == null)
                {
                    return null;
                }

                ModelInputObject model =  GetInputObject(ChildDataID, connectString, ChildDatasTableName,new AccountOffline());

                if ((model!=null) &&(model.DataStoreID != null))
                {
                    model.FileSize = dataSotre.GetFileSize(model.DataStoreID);
                }
                return model;
            }
            catch (Exception ex)
            {
                throw ex;
            }
 
           
         
           
        }

        public override List<ModelOrderRecord> GetChildID(Guid orderID)
        { 
            try
            {
                if (orderID == null)
                {
                    return null;
                }

                return GetChildID(orderID, connectString, ChildDatasTableName);
                
            }
            catch (Exception ex)
            {
                throw ex;
            } 


        }

        public override Guid GetParentID(  Guid ChildDataID)
        {
           
            try
            { 
                return GetParentID(ChildDataID, connectString, ChildDatasTableName);
            }
            catch (Exception ex)
            {
                throw ex;
            }

          
        }

        public override  BlockImage GetBlockImage(Guid FrameID, int Left, int Top, int Width, int Height)
        {
            try
            {
                return GetBlockImage(FrameID,  Left,  Top,  Width,  Height, connectString, ChildDatasTableName);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public override List<ModelFrameResult> GetFrameResult(Guid ChildDataID)
        {
            try
            {
                if (ChildDataID == null)
                {
                    return null;
                }


                List<ModelFrameResult> modelList = GetFrameResult(ChildDataID, connectString, ChildDatasTableName);

                if (modelList != null)  
                {
                    foreach (ModelFrameResult model in modelList)
                    {
                         model.FileSize = dataSotre.GetFileSize(model.DataStoreID);
                    }
                   
                }
                return modelList;
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }
    }   
}

